# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=pybind11
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.11.1
pkgrel=1
pkgdesc="A lightweight header-only library that exposes C++ types in Python and vice versa (mingw-w64)"
url='https://pybind11.readthedocs.org/'
license=('BSD')
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-eigen3"
             "${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-python-breathe"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx_rtd_theme"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx-copybutton"
             "${MINGW_PACKAGE_PREFIX}-python-sphinxcontrib-moderncmakedomain"
             "${MINGW_PACKAGE_PREFIX}-python-sphinxcontrib-svg2pdfconverter"
             "${MINGW_PACKAGE_PREFIX}-python-pytest")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/pybind/pybind11/archive/v${pkgver}.tar.gz")
sha256sums=('d475978da0cdc2d43b73f30910786759d593a9d8ee05b1b6846d1eb16c6d2e0c')

build () {
  cd "${srcdir}/${_realname}-${pkgver}"
  ${MINGW_PREFIX}/bin/python setup.py build

  cd "${srcdir}/${_realname}-${pkgver}/build"
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DPYTHON_EXECUTABLE=${MINGW_PREFIX}/bin/python \
    ..
  ${MINGW_PREFIX}/bin/cmake --build . --target mock_install

  cd "${srcdir}/${_realname}-${pkgver}/docs"
  make man
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}/build"
  DESTDIR="$pkgdir" ${MINGW_PREFIX}/bin/cmake --install .

  # python modules
  cd "${srcdir}/${_realname}-${pkgver}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --skip-build --optimize='1'

  # C++ headers
  #cd "${srcdir}/${_realname}-${pkgver}"
  #MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  #${MINGW_PREFIX}/bin/python setup.py install_headers --install-dir="${pkgdir}${MINGW_PREFIX}/include/${_realname}"

  # cmake files
  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/cmake/${_realname}"
  cd build/mock_install/share/cmake/pybind11
  install -m644 *.cmake "${pkgdir}${MINGW_PREFIX}/share/cmake/${_realname}"

  # manpage
  cd "${srcdir}/${_realname}-${pkgver}/docs/.build/man"
  install -D -m644 "${_realname}.1" -t "${pkgdir}${MINGW_PREFIX}/share/man/man1"

  # license
  install -D -m644 ${srcdir}/${_realname}-${pkgver}/LICENSE -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
